package com.github.aloxc.plugin.restplus.test;


import com.github.aloxc.plugin.DonotGuard;
import com.github.aloxc.plugin.restplus.entity.HttpResponseContentType;
import com.github.aloxc.plugin.restplus.entity.HttpResponseHeaders;
import com.github.aloxc.plugin.restplus.test.impl.HttpClientExternal;
import org.apache.http.entity.ContentType;
import org.jetbrains.annotations.NotNull;

import java.nio.charset.Charset;
import java.util.List;
/**
 * @author leero
 */
@DonotGuard
public class RestResponse {
    @DonotGuard
    private HttpClientExternal client;
    @DonotGuard
    private HttpResponseHeaders headers;
    @DonotGuard
    private HttpResponseContentType contentType;
    @DonotGuard
    private String content;
    @DonotGuard
    private int statusCode;
    @DonotGuard
    private List<TestResult> testResultList;
    @DonotGuard
    private List<Object> printList;
    public HttpClientExternal getClient() {
        return client;
    }


    public void setClient(HttpClientExternal client) {
        this.client = client;
    }

    public List<Object> getPrintList() {
        return printList;
    }

    public void setPrintList(List<Object> printList) {
        this.printList = printList;
    }

    public HttpResponseHeaders getHeaders() {
        return headers;
    }

    public void setHeaders(HttpResponseHeaders headers) {
        this.headers = headers;
    }

    public HttpResponseContentType getContentType() {
        return contentType;
    }

    public void setContentType(HttpResponseContentType contentType) {
        this.contentType = contentType;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }

    public List<TestResult> getTestResultList() {
        return testResultList;
    }

    public void setTestResultList(List<TestResult> testResultList) {
        this.testResultList = testResultList;
    }

    public RestResponse(@NotNull HttpClientExternal client, @NotNull HttpResponseHeaders headers, @NotNull HttpResponseContentType contentType, @NotNull String content, int statusCode) {
        this.client = client;
        this.headers = headers;
        this.contentType = contentType;
        this.content = content;
        this.statusCode = statusCode;
    }

    @NotNull
    public static RestResponse create(@NotNull RestClientResponse response) {
        HttpClientExternal client = new HttpClientExternal();
        HttpResponseHeaders headers = new HttpResponseHeaders(response.getAllHeaders());
        ContentType type = response.getContentType();
        Charset charset = type.getCharset();
        HttpResponseContentType contentType = new HttpResponseContentType(type.getMimeType(), (charset != null) ? charset.name() : "");
        return new RestResponse(client, headers, contentType, response.getContent(), response.getStatusLine().getStatusCode());
    }


}